package net.bmwgroup.easyrule.demo.actions;


import org.jeasy.rules.api.Action;
import org.jeasy.rules.api.Facts;

import java.util.ArrayList;
import java.util.List;

public class ActionExecutor {

    private List<Action> actions = new ArrayList<>();
    private Facts facts;

    public ActionExecutor(Facts facts) {
        this.facts = facts;
    }
    public void setAction(Action action) {
        this.actions.add(action);
    }

//    public void executeAction(Action action, Facts facts) throws Exception {
//        action.execute(facts);
//    }

    public void execute() {
        actions.forEach(action -> {
            try {
                action.execute(facts);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        actions.clear();
    }
}
